#ifndef CPANEL_H
#define CPANEL_H

#include <vector>
#include "C3DPoint.h"

using std::vector;

enum PanelShape{Rectangle, Triangle};

class CPanel
{
	public:
		CPanel();	//constructor
		~CPanel();	//deconstructor

		double 	GetLongestSideValue() const;				//get the value of longest side
		int 	GetLongestSideIndex() const;				//get the index of longest side
		double	GetShortestSideValue() const;				//get shortest side value
		double 	GetPotential(const CPanel &A) const;		//get the potential between 2 panels
		double	GetRatio() const;							//get length-width ratio

		unsigned int GetCondNum() const;		//get the condNum of panel
		unsigned int GetLeft() const;			//get left child
		unsigned int GetRight() const;			//get right child
		unsigned int GetParent() const;			//get parent
		unsigned int GetRoot() const;			//get root of current panel
		unsigned int GetBasisIndex() const;		//get basis index
		int GetNodeType() const;				//get node type, 0: root, 1: left, 2: right

		//input the panel information
		void InputPanel(const int Pshape, const unsigned int condNum, const double Coord[], const unsigned int panelNum);
		//divide panel and create 2 new subpanels
		void PanelPartition(vector<CPanel*> &panelList, unsigned int &panelNum, int &basisNum);
		//decide whether the 2 panels should be divided or not
		bool Decision(const CPanel &A, const double *err);
		bool isCut() const;			//check panel state, if it's not divided yet, return true

		//for testing
		C3DPoint GetPanelVertex(const int Pindex) const;

	private:
		//Panel parameters
		unsigned int cond_number;	//conductor number

		enum PanelShape shape;		//panel shape
		C3DPoint 		index[4];	//4 vertices
		bool 			side[4];	//edge is true and inner line is fault
		C3DPoint 		center;		//center of panel
		double 			area;		//area of panel
		int				ntype;		//node type in binary tree

		//Node parameters
		unsigned int root;			//the very beginning panel index
		unsigned int Vindex;		//tree index in panel vector
		unsigned int parent;		//parent of current panel
		unsigned int left;			//left child of current panel
		unsigned int right;			//right child of current panel
		unsigned int basis_index;	//basis index

		bool cut_flag;		//the flag which deciding further dividing

		double 	Heron(const double, const double, const double);		//Heron method
		void 	Assign(CPanel&) const;	//assign the new panel as same as this panel	
		void 	FindCenter();			//find center point of panel
		void 	FindArea();			//find area of panel

		C3DPoint GetCenter() const;		//get the coordinate of center in a panel
};

#endif
